{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 这个程序最好在本地机器上运行 花费时间非常巨大 数据量很大 训练也很大 这里只是将代码写好 后续有时间回来再补"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint8 = np.dtype([(\"qint8\", np.int8, 1)])\n",
      "/home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_quint8 = np.dtype([(\"quint8\", np.uint8, 1)])\n",
      "/home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:528: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint16 = np.dtype([(\"qint16\", np.int16, 1)])\n",
      "/home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:529: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_quint16 = np.dtype([(\"quint16\", np.uint16, 1)])\n",
      "/home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:530: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint32 = np.dtype([(\"qint32\", np.int32, 1)])\n",
      "/home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:535: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  np_resource = np.dtype([(\"resource\", np.ubyte, 1)])\n"
     ]
    }
   ],
   "source": [
    "#加载数据\n",
    "import pandas as pd\n",
    "import pickle\n",
    "from tensorflow import keras\n",
    "from tensorflow.keras.models import Sequential\n",
    "from tensorflow.keras.layers import Dense,Dropout\n",
    "from tensorflow.keras import regularizers\n",
    "from tensorflow.keras.utils import to_categorical"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 下面几行的读取df_train3.pkl和df_test3.pkl都是没有用的 代码和数据可以删掉了"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "pickle文件读取完毕\n"
     ]
    }
   ],
   "source": [
    "# with open(\"./df_train3.pkl\",'rb') as f:\n",
    "#     df_train=pickle.load(f)\n",
    "\n",
    "# with open(\"./df_test3.pkl\",'rb') as f:\n",
    "#     df_test=pickle.load(f)\n",
    "# print(\"pickle文件读取完毕\")  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>file_id</th>\n",
       "      <th>label</th>\n",
       "      <th>api_count</th>\n",
       "      <th>api_nunique</th>\n",
       "      <th>api_min</th>\n",
       "      <th>api_max</th>\n",
       "      <th>api_mean</th>\n",
       "      <th>api_median</th>\n",
       "      <th>api_std</th>\n",
       "      <th>api_ptp</th>\n",
       "      <th>...</th>\n",
       "      <th>wsastartup ntallocatevirtualmemory ntfreevirtualmemory</th>\n",
       "      <th>wsastartup regopenkeyexa</th>\n",
       "      <th>wsastartup regopenkeyexa regqueryvalueexa</th>\n",
       "      <th>wsastartup regopenkeyexa regsetvalueexa</th>\n",
       "      <th>wsastartup socket</th>\n",
       "      <th>wsastartup socket bind</th>\n",
       "      <th>wsastartup socket ntqueryattributesfile</th>\n",
       "      <th>wsastartup wsastartup</th>\n",
       "      <th>wsastartup wsastartup findresourceexw</th>\n",
       "      <th>wsastartup wsastartup socket</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "      <td>6786</td>\n",
       "      <td>116</td>\n",
       "      <td>6</td>\n",
       "      <td>298</td>\n",
       "      <td>171.965223</td>\n",
       "      <td>172.0</td>\n",
       "      <td>67.767773</td>\n",
       "      <td>292</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000721</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00192</td>\n",
       "      <td>0.003114</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.002741</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000774</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>816</td>\n",
       "      <td>30</td>\n",
       "      <td>89</td>\n",
       "      <td>298</td>\n",
       "      <td>159.696078</td>\n",
       "      <td>153.0</td>\n",
       "      <td>35.746150</td>\n",
       "      <td>209</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.02643</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.028152</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>463</td>\n",
       "      <td>42</td>\n",
       "      <td>9</td>\n",
       "      <td>258</td>\n",
       "      <td>164.948164</td>\n",
       "      <td>151.0</td>\n",
       "      <td>51.508095</td>\n",
       "      <td>249</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>2046</td>\n",
       "      <td>51</td>\n",
       "      <td>9</td>\n",
       "      <td>257</td>\n",
       "      <td>154.939883</td>\n",
       "      <td>151.0</td>\n",
       "      <td>48.451188</td>\n",
       "      <td>248</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>10002</td>\n",
       "      <td>65</td>\n",
       "      <td>6</td>\n",
       "      <td>254</td>\n",
       "      <td>201.893421</td>\n",
       "      <td>227.0</td>\n",
       "      <td>42.833942</td>\n",
       "      <td>248</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13882</th>\n",
       "      <td>13883</td>\n",
       "      <td>2</td>\n",
       "      <td>178221</td>\n",
       "      <td>71</td>\n",
       "      <td>6</td>\n",
       "      <td>279</td>\n",
       "      <td>156.643100</td>\n",
       "      <td>152.0</td>\n",
       "      <td>59.406387</td>\n",
       "      <td>273</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13883</th>\n",
       "      <td>13884</td>\n",
       "      <td>5</td>\n",
       "      <td>1319</td>\n",
       "      <td>39</td>\n",
       "      <td>6</td>\n",
       "      <td>279</td>\n",
       "      <td>163.025019</td>\n",
       "      <td>139.0</td>\n",
       "      <td>83.388118</td>\n",
       "      <td>273</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13884</th>\n",
       "      <td>13885</td>\n",
       "      <td>0</td>\n",
       "      <td>1033</td>\n",
       "      <td>71</td>\n",
       "      <td>8</td>\n",
       "      <td>259</td>\n",
       "      <td>174.896418</td>\n",
       "      <td>170.0</td>\n",
       "      <td>50.035123</td>\n",
       "      <td>251</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13885</th>\n",
       "      <td>13886</td>\n",
       "      <td>1</td>\n",
       "      <td>5316</td>\n",
       "      <td>80</td>\n",
       "      <td>9</td>\n",
       "      <td>281</td>\n",
       "      <td>168.313017</td>\n",
       "      <td>167.0</td>\n",
       "      <td>57.440981</td>\n",
       "      <td>272</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13886</th>\n",
       "      <td>13887</td>\n",
       "      <td>2</td>\n",
       "      <td>623</td>\n",
       "      <td>37</td>\n",
       "      <td>11</td>\n",
       "      <td>277</td>\n",
       "      <td>139.784912</td>\n",
       "      <td>134.0</td>\n",
       "      <td>23.274304</td>\n",
       "      <td>266</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>13887 rows × 7640 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       file_id  label  api_count  api_nunique  api_min  api_max    api_mean  \\\n",
       "0            1      5       6786          116        6      298  171.965223   \n",
       "1            2      2        816           30       89      298  159.696078   \n",
       "2            3      0        463           42        9      258  164.948164   \n",
       "3            4      0       2046           51        9      257  154.939883   \n",
       "4            5      0      10002           65        6      254  201.893421   \n",
       "...        ...    ...        ...          ...      ...      ...         ...   \n",
       "13882    13883      2     178221           71        6      279  156.643100   \n",
       "13883    13884      5       1319           39        6      279  163.025019   \n",
       "13884    13885      0       1033           71        8      259  174.896418   \n",
       "13885    13886      1       5316           80        9      281  168.313017   \n",
       "13886    13887      2        623           37       11      277  139.784912   \n",
       "\n",
       "       api_median    api_std  api_ptp  ...  \\\n",
       "0           172.0  67.767773      292  ...   \n",
       "1           153.0  35.746150      209  ...   \n",
       "2           151.0  51.508095      249  ...   \n",
       "3           151.0  48.451188      248  ...   \n",
       "4           227.0  42.833942      248  ...   \n",
       "...           ...        ...      ...  ...   \n",
       "13882       152.0  59.406387      273  ...   \n",
       "13883       139.0  83.388118      273  ...   \n",
       "13884       170.0  50.035123      251  ...   \n",
       "13885       167.0  57.440981      272  ...   \n",
       "13886       134.0  23.274304      266  ...   \n",
       "\n",
       "       wsastartup ntallocatevirtualmemory ntfreevirtualmemory  \\\n",
       "0                                               0.000721        \n",
       "1                                               0.000000        \n",
       "2                                               0.000000        \n",
       "3                                               0.000000        \n",
       "4                                               0.000000        \n",
       "...                                                  ...        \n",
       "13882                                           0.000000        \n",
       "13883                                           0.000000        \n",
       "13884                                           0.000000        \n",
       "13885                                           0.000000        \n",
       "13886                                           0.000000        \n",
       "\n",
       "       wsastartup regopenkeyexa  wsastartup regopenkeyexa regqueryvalueexa  \\\n",
       "0                           0.0                                        0.0   \n",
       "1                           0.0                                        0.0   \n",
       "2                           0.0                                        0.0   \n",
       "3                           0.0                                        0.0   \n",
       "4                           0.0                                        0.0   \n",
       "...                         ...                                        ...   \n",
       "13882                       0.0                                        0.0   \n",
       "13883                       0.0                                        0.0   \n",
       "13884                       0.0                                        0.0   \n",
       "13885                       0.0                                        0.0   \n",
       "13886                       0.0                                        0.0   \n",
       "\n",
       "       wsastartup regopenkeyexa regsetvalueexa  wsastartup socket  \\\n",
       "0                                          0.0            0.00192   \n",
       "1                                          0.0            0.02643   \n",
       "2                                          0.0            0.00000   \n",
       "3                                          0.0            0.00000   \n",
       "4                                          0.0            0.00000   \n",
       "...                                        ...                ...   \n",
       "13882                                      0.0            0.00000   \n",
       "13883                                      0.0            0.00000   \n",
       "13884                                      0.0            0.00000   \n",
       "13885                                      0.0            0.00000   \n",
       "13886                                      0.0            0.00000   \n",
       "\n",
       "       wsastartup socket bind  wsastartup socket ntqueryattributesfile  \\\n",
       "0                    0.003114                                 0.000000   \n",
       "1                    0.000000                                 0.028152   \n",
       "2                    0.000000                                 0.000000   \n",
       "3                    0.000000                                 0.000000   \n",
       "4                    0.000000                                 0.000000   \n",
       "...                       ...                                      ...   \n",
       "13882                0.000000                                 0.000000   \n",
       "13883                0.000000                                 0.000000   \n",
       "13884                0.000000                                 0.000000   \n",
       "13885                0.000000                                 0.000000   \n",
       "13886                0.000000                                 0.000000   \n",
       "\n",
       "       wsastartup wsastartup  wsastartup wsastartup findresourceexw  \\\n",
       "0                   0.002741                                    0.0   \n",
       "1                   0.000000                                    0.0   \n",
       "2                   0.000000                                    0.0   \n",
       "3                   0.000000                                    0.0   \n",
       "4                   0.000000                                    0.0   \n",
       "...                      ...                                    ...   \n",
       "13882               0.000000                                    0.0   \n",
       "13883               0.000000                                    0.0   \n",
       "13884               0.000000                                    0.0   \n",
       "13885               0.000000                                    0.0   \n",
       "13886               0.000000                                    0.0   \n",
       "\n",
       "       wsastartup wsastartup socket  \n",
       "0                          0.000774  \n",
       "1                          0.000000  \n",
       "2                          0.000000  \n",
       "3                          0.000000  \n",
       "4                          0.000000  \n",
       "...                             ...  \n",
       "13882                      0.000000  \n",
       "13883                      0.000000  \n",
       "13884                      0.000000  \n",
       "13885                      0.000000  \n",
       "13886                      0.000000  \n",
       "\n",
       "[13887 rows x 7640 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# df_train"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>file_id</th>\n",
       "      <th>api_count</th>\n",
       "      <th>api_nunique</th>\n",
       "      <th>api_min</th>\n",
       "      <th>api_max</th>\n",
       "      <th>api_mean</th>\n",
       "      <th>api_median</th>\n",
       "      <th>api_std</th>\n",
       "      <th>api_ptp</th>\n",
       "      <th>tid_count</th>\n",
       "      <th>...</th>\n",
       "      <th>wsastartup ntallocatevirtualmemory ntfreevirtualmemory</th>\n",
       "      <th>wsastartup regopenkeyexa</th>\n",
       "      <th>wsastartup regopenkeyexa regqueryvalueexa</th>\n",
       "      <th>wsastartup regopenkeyexa regsetvalueexa</th>\n",
       "      <th>wsastartup socket</th>\n",
       "      <th>wsastartup socket bind</th>\n",
       "      <th>wsastartup socket ntqueryattributesfile</th>\n",
       "      <th>wsastartup wsastartup</th>\n",
       "      <th>wsastartup wsastartup findresourceexw</th>\n",
       "      <th>wsastartup wsastartup socket</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>97</td>\n",
       "      <td>15</td>\n",
       "      <td>13</td>\n",
       "      <td>262</td>\n",
       "      <td>155.989691</td>\n",
       "      <td>152.0</td>\n",
       "      <td>50.338954</td>\n",
       "      <td>249</td>\n",
       "      <td>97</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000721</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00192</td>\n",
       "      <td>0.003114</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.002741</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000774</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>1361</td>\n",
       "      <td>40</td>\n",
       "      <td>6</td>\n",
       "      <td>261</td>\n",
       "      <td>138.025716</td>\n",
       "      <td>138.0</td>\n",
       "      <td>49.557795</td>\n",
       "      <td>255</td>\n",
       "      <td>1361</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.02643</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.028152</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>16</td>\n",
       "      <td>9</td>\n",
       "      <td>16</td>\n",
       "      <td>257</td>\n",
       "      <td>111.375000</td>\n",
       "      <td>134.0</td>\n",
       "      <td>75.152179</td>\n",
       "      <td>241</td>\n",
       "      <td>16</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>193</td>\n",
       "      <td>34</td>\n",
       "      <td>13</td>\n",
       "      <td>262</td>\n",
       "      <td>172.217617</td>\n",
       "      <td>170.0</td>\n",
       "      <td>45.377632</td>\n",
       "      <td>249</td>\n",
       "      <td>193</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>803</td>\n",
       "      <td>34</td>\n",
       "      <td>16</td>\n",
       "      <td>261</td>\n",
       "      <td>168.490660</td>\n",
       "      <td>153.0</td>\n",
       "      <td>55.316733</td>\n",
       "      <td>245</td>\n",
       "      <td>803</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12950</th>\n",
       "      <td>12951</td>\n",
       "      <td>289</td>\n",
       "      <td>37</td>\n",
       "      <td>9</td>\n",
       "      <td>269</td>\n",
       "      <td>140.536332</td>\n",
       "      <td>151.0</td>\n",
       "      <td>63.718398</td>\n",
       "      <td>260</td>\n",
       "      <td>289</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12951</th>\n",
       "      <td>12952</td>\n",
       "      <td>112</td>\n",
       "      <td>28</td>\n",
       "      <td>56</td>\n",
       "      <td>261</td>\n",
       "      <td>163.669643</td>\n",
       "      <td>152.0</td>\n",
       "      <td>42.920708</td>\n",
       "      <td>205</td>\n",
       "      <td>112</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12952</th>\n",
       "      <td>12953</td>\n",
       "      <td>5095</td>\n",
       "      <td>72</td>\n",
       "      <td>6</td>\n",
       "      <td>286</td>\n",
       "      <td>200.063199</td>\n",
       "      <td>214.0</td>\n",
       "      <td>63.838795</td>\n",
       "      <td>280</td>\n",
       "      <td>5095</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12953</th>\n",
       "      <td>12954</td>\n",
       "      <td>2951</td>\n",
       "      <td>65</td>\n",
       "      <td>9</td>\n",
       "      <td>298</td>\n",
       "      <td>191.007794</td>\n",
       "      <td>139.0</td>\n",
       "      <td>69.088685</td>\n",
       "      <td>289</td>\n",
       "      <td>2951</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12954</th>\n",
       "      <td>12955</td>\n",
       "      <td>2038</td>\n",
       "      <td>54</td>\n",
       "      <td>13</td>\n",
       "      <td>284</td>\n",
       "      <td>208.845927</td>\n",
       "      <td>266.0</td>\n",
       "      <td>64.245707</td>\n",
       "      <td>271</td>\n",
       "      <td>2038</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>12955 rows × 7639 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       file_id  api_count  api_nunique  api_min  api_max    api_mean  \\\n",
       "0            1         97           15       13      262  155.989691   \n",
       "1            2       1361           40        6      261  138.025716   \n",
       "2            3         16            9       16      257  111.375000   \n",
       "3            4        193           34       13      262  172.217617   \n",
       "4            5        803           34       16      261  168.490660   \n",
       "...        ...        ...          ...      ...      ...         ...   \n",
       "12950    12951        289           37        9      269  140.536332   \n",
       "12951    12952        112           28       56      261  163.669643   \n",
       "12952    12953       5095           72        6      286  200.063199   \n",
       "12953    12954       2951           65        9      298  191.007794   \n",
       "12954    12955       2038           54       13      284  208.845927   \n",
       "\n",
       "       api_median    api_std  api_ptp  tid_count  ...  \\\n",
       "0           152.0  50.338954      249         97  ...   \n",
       "1           138.0  49.557795      255       1361  ...   \n",
       "2           134.0  75.152179      241         16  ...   \n",
       "3           170.0  45.377632      249        193  ...   \n",
       "4           153.0  55.316733      245        803  ...   \n",
       "...           ...        ...      ...        ...  ...   \n",
       "12950       151.0  63.718398      260        289  ...   \n",
       "12951       152.0  42.920708      205        112  ...   \n",
       "12952       214.0  63.838795      280       5095  ...   \n",
       "12953       139.0  69.088685      289       2951  ...   \n",
       "12954       266.0  64.245707      271       2038  ...   \n",
       "\n",
       "       wsastartup ntallocatevirtualmemory ntfreevirtualmemory  \\\n",
       "0                                               0.000721        \n",
       "1                                               0.000000        \n",
       "2                                               0.000000        \n",
       "3                                               0.000000        \n",
       "4                                               0.000000        \n",
       "...                                                  ...        \n",
       "12950                                           0.000000        \n",
       "12951                                           0.000000        \n",
       "12952                                           0.000000        \n",
       "12953                                           0.000000        \n",
       "12954                                           0.000000        \n",
       "\n",
       "       wsastartup regopenkeyexa  wsastartup regopenkeyexa regqueryvalueexa  \\\n",
       "0                           0.0                                        0.0   \n",
       "1                           0.0                                        0.0   \n",
       "2                           0.0                                        0.0   \n",
       "3                           0.0                                        0.0   \n",
       "4                           0.0                                        0.0   \n",
       "...                         ...                                        ...   \n",
       "12950                       0.0                                        0.0   \n",
       "12951                       0.0                                        0.0   \n",
       "12952                       0.0                                        0.0   \n",
       "12953                       0.0                                        0.0   \n",
       "12954                       0.0                                        0.0   \n",
       "\n",
       "       wsastartup regopenkeyexa regsetvalueexa  wsastartup socket  \\\n",
       "0                                          0.0            0.00192   \n",
       "1                                          0.0            0.02643   \n",
       "2                                          0.0            0.00000   \n",
       "3                                          0.0            0.00000   \n",
       "4                                          0.0            0.00000   \n",
       "...                                        ...                ...   \n",
       "12950                                      0.0            0.00000   \n",
       "12951                                      0.0            0.00000   \n",
       "12952                                      0.0            0.00000   \n",
       "12953                                      0.0            0.00000   \n",
       "12954                                      0.0            0.00000   \n",
       "\n",
       "       wsastartup socket bind  wsastartup socket ntqueryattributesfile  \\\n",
       "0                    0.003114                                 0.000000   \n",
       "1                    0.000000                                 0.028152   \n",
       "2                    0.000000                                 0.000000   \n",
       "3                    0.000000                                 0.000000   \n",
       "4                    0.000000                                 0.000000   \n",
       "...                       ...                                      ...   \n",
       "12950                0.000000                                 0.000000   \n",
       "12951                0.000000                                 0.000000   \n",
       "12952                0.000000                                 0.000000   \n",
       "12953                0.000000                                 0.000000   \n",
       "12954                0.000000                                 0.000000   \n",
       "\n",
       "       wsastartup wsastartup  wsastartup wsastartup findresourceexw  \\\n",
       "0                   0.002741                                    0.0   \n",
       "1                   0.000000                                    0.0   \n",
       "2                   0.000000                                    0.0   \n",
       "3                   0.000000                                    0.0   \n",
       "4                   0.000000                                    0.0   \n",
       "...                      ...                                    ...   \n",
       "12950               0.000000                                    0.0   \n",
       "12951               0.000000                                    0.0   \n",
       "12952               0.000000                                    0.0   \n",
       "12953               0.000000                                    0.0   \n",
       "12954               0.000000                                    0.0   \n",
       "\n",
       "       wsastartup wsastartup socket  \n",
       "0                          0.000774  \n",
       "1                          0.000000  \n",
       "2                          0.000000  \n",
       "3                          0.000000  \n",
       "4                          0.000000  \n",
       "...                             ...  \n",
       "12950                      0.000000  \n",
       "12951                      0.000000  \n",
       "12952                      0.000000  \n",
       "12953                      0.000000  \n",
       "12954                      0.000000  \n",
       "\n",
       "[12955 rows x 7639 columns]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# df_test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0        5\n",
       "1        2\n",
       "2        0\n",
       "3        0\n",
       "4        0\n",
       "        ..\n",
       "13882    2\n",
       "13883    5\n",
       "13884    0\n",
       "13885    1\n",
       "13886    2\n",
       "Name: label, Length: 13887, dtype: int64"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# df_train_y=df_train['label']\n",
    "# df_train_y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5 [0. 0. 0. 0. 0. 1. 0. 0.]\n",
      "2 [0. 0. 1. 0. 0. 0. 0. 0.]\n",
      "0 [1. 0. 0. 0. 0. 0. 0. 0.]\n"
     ]
    }
   ],
   "source": [
    "# labels=to_categorical(df_train_y)\n",
    "# print(df_train_y[0],labels[0])\n",
    "# print(df_train_y[1],labels[1])\n",
    "# print(df_train_y[2],labels[2])#果然是把原来的标签转成了ont_hot编码 之所以这么做是因为神经网络的需要"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 从这里开始 重新读取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(89806693, 5) (89806693, 5)\n"
     ]
    }
   ],
   "source": [
    "##做到这里 最终还是用最开始的数据集了 数据量有点大   所以上面几行的读取df_train3.pkl和df_test3.pkl都是没有用的 代码和数据可以删掉了\n",
    "df_train=pd.read_csv('./security_train.csv')\n",
    "df_test=pd.read_csv('./security_train.csv')\n",
    "print(df_train.shape,df_test.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0           5\n",
       "1           5\n",
       "2           5\n",
       "3           5\n",
       "4           5\n",
       "           ..\n",
       "89806688    2\n",
       "89806689    2\n",
       "89806690    2\n",
       "89806691    2\n",
       "89806692    2\n",
       "Name: label, Length: 89806693, dtype: int64"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_train_y=df_train['label']\n",
    "df_train_y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5 [0. 0. 0. 0. 0. 1. 0. 0.]\n",
      "5 [0. 0. 0. 0. 0. 1. 0. 0.]\n",
      "5 [0. 0. 0. 0. 0. 1. 0. 0.]\n"
     ]
    }
   ],
   "source": [
    "labels=to_categorical(df_train_y)\n",
    "print(df_train_y[0],labels[0])\n",
    "print(df_train_y[1],labels[1])\n",
    "print(df_train_y[2],labels[2])#果然是把原来的标签转成了ont_hot编码 之所以这么做是因为神经网络的需要"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "from keras_preprocessing.text import Tokenizer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'ldrgetprocedureaddress': 1,\n",
       " 'ntclose': 2,\n",
       " 'regqueryvalueexw': 3,\n",
       " 'thread32next': 4,\n",
       " 'ntdelayexecution': 5,\n",
       " 'regopenkeyexw': 6,\n",
       " 'regclosekey': 7,\n",
       " 'getsystemmetrics': 8,\n",
       " 'getcursorpos': 9,\n",
       " 'ntreadfile': 10,\n",
       " 'ntallocatevirtualmemory': 11,\n",
       " 'process32nextw': 12,\n",
       " 'ntqueryvaluekey': 13,\n",
       " 'ntwritefile': 14,\n",
       " 'getkeystate': 15,\n",
       " 'ldrloaddll': 16,\n",
       " 'getforegroundwindow': 17,\n",
       " 'getsystemtimeasfiletime': 18,\n",
       " 'ntquerydirectoryfile': 19,\n",
       " 'loadstringw': 20,\n",
       " 'findfirstfileexw': 21,\n",
       " 'ntquerykey': 22,\n",
       " 'ntopenkey': 23,\n",
       " 'ntcreatefile': 24,\n",
       " 'ldrgetdllhandle': 25,\n",
       " 'ntopenkeyex': 26,\n",
       " 'cryptdecodeobjectex': 27,\n",
       " 'ntprotectvirtualmemory': 28,\n",
       " 'ntfreevirtualmemory': 29,\n",
       " 'setfilepointer': 30,\n",
       " 'timegettime': 31,\n",
       " 'getfiletype': 32,\n",
       " 'loadresource': 33,\n",
       " 'regqueryvalueexa': 34,\n",
       " 'readprocessmemory': 35,\n",
       " 'getfileattributesw': 36,\n",
       " 'seterrormode': 37,\n",
       " 'findresourceexw': 38,\n",
       " 'ntmapviewofsection': 39,\n",
       " 'regopenkeyexa': 40,\n",
       " 'ntcreatesection': 41,\n",
       " 'loadstringa': 42,\n",
       " 'ntunmapviewofsection': 43,\n",
       " 'regenumkeyexw': 44,\n",
       " 'cocreateinstance': 45,\n",
       " 'ntopenfile': 46,\n",
       " 'writeconsolew': 47,\n",
       " 'regenumvaluew': 48,\n",
       " 'ldrunloaddll': 49,\n",
       " 'ntdeviceiocontrolfile': 50,\n",
       " 'regsetvalueexa': 51,\n",
       " 'ntopenprocess': 52,\n",
       " 'ntqueryinformationfile': 53,\n",
       " 'writeconsolea': 54,\n",
       " 'ntqueryattributesfile': 55,\n",
       " 'getsysteminfo': 56,\n",
       " 'regenumkeyw': 57,\n",
       " 'ntcreatemutant': 58,\n",
       " 'ntterminateprocess': 59,\n",
       " 'ntduplicateobject': 60,\n",
       " 'exception': 61,\n",
       " 'createthread': 62,\n",
       " 'drawtextexa': 63,\n",
       " 'getsystemwindowsdirectoryw': 64,\n",
       " 'regenumkeyexa': 65,\n",
       " 'couninitialize': 66,\n",
       " 'coinitializeex': 67,\n",
       " 'getfilesize': 68,\n",
       " 'getasynckeystate': 69,\n",
       " 'findwindowexw': 70,\n",
       " 'ntreadvirtualmemory': 71,\n",
       " 'sizeofresource': 72,\n",
       " 'findresourcew': 73,\n",
       " 'drawtextexw': 74,\n",
       " 'ntopensection': 75,\n",
       " 'ntopenmutant': 76,\n",
       " 'getfileattributesexw': 77,\n",
       " 'closesocket': 78,\n",
       " 'socket': 79,\n",
       " 'regcreatekeyexw': 80,\n",
       " 'setfilepointerex': 81,\n",
       " 'writeprocessmemory': 82,\n",
       " 'getsystemdirectoryw': 83,\n",
       " 'ntquerysysteminformation': 84,\n",
       " 'regqueryinfokeya': 85,\n",
       " 'deviceiocontrol': 86,\n",
       " 'ntenumeratevaluekey': 87,\n",
       " 'ntenumeratekey': 88,\n",
       " 'crypthashdata': 89,\n",
       " 'regqueryinfokeyw': 90,\n",
       " 'setunhandledexceptionfilter': 91,\n",
       " 'select': 92,\n",
       " 'regdeletevaluew': 93,\n",
       " 'createdirectoryw': 94,\n",
       " 'regsetvalueexw': 95,\n",
       " 'setfileattributesw': 96,\n",
       " 'wsastartup': 97,\n",
       " 'getvolumepathnamesforvolumenamew': 98,\n",
       " 'createtoolhelp32snapshot': 99,\n",
       " 'shgetfolderpathw': 100,\n",
       " 'internetopena': 101,\n",
       " 'createprocessinternalw': 102,\n",
       " 'getnativesysteminfo': 103,\n",
       " 'ntresumethread': 104,\n",
       " 'ntsetinformationfile': 105,\n",
       " 'process32firstw': 106,\n",
       " 'connect': 107,\n",
       " 'setendoffile': 108,\n",
       " 'setsockopt': 109,\n",
       " 'findresourcea': 110,\n",
       " 'enumwindows': 111,\n",
       " 'regcreatekeyexa': 112,\n",
       " 'searchpathw': 113,\n",
       " 'ntopendirectoryobject': 114,\n",
       " 'internetopenurla': 115,\n",
       " 'findwindowa': 116,\n",
       " 'ntsetvaluekey': 117,\n",
       " 'setstdhandle': 118,\n",
       " 'getshortpathnamew': 119,\n",
       " 'setfiletime': 120,\n",
       " 'gettemppathw': 121,\n",
       " 'globalmemorystatusex': 122,\n",
       " 'getaddrinfo': 123,\n",
       " 'getvolumenameforvolumemountpointw': 124,\n",
       " 'ntopenthread': 125,\n",
       " 'deletefilew': 126,\n",
       " 'getfilesizeex': 127,\n",
       " 'gethostbyname': 128,\n",
       " 'createactctxw': 129,\n",
       " 'cryptdecrypt': 130,\n",
       " 'oleinitialize': 131,\n",
       " 'lookupprivilegevaluew': 132,\n",
       " 'send': 133,\n",
       " 'cryptcreatehash': 134,\n",
       " 'module32nextw': 135,\n",
       " 'ntcreatekey': 136,\n",
       " 'findwindowexa': 137,\n",
       " 'cogetclassobject': 138,\n",
       " 'openscmanagera': 139,\n",
       " 'internetsetoptiona': 140,\n",
       " 'regenumvaluea': 141,\n",
       " 'internetclosehandle': 142,\n",
       " 'getadaptersaddresses': 143,\n",
       " 'ntcreatethreadex': 144,\n",
       " 'copyfilea': 145,\n",
       " 'getfileinformationbyhandleex': 146,\n",
       " 'getkeyboardstate': 147,\n",
       " 'findwindoww': 148,\n",
       " 'uuidcreate': 149,\n",
       " 'openservicea': 150,\n",
       " 'isdebuggerpresent': 151,\n",
       " 'gettimezoneinformation': 152,\n",
       " 'openservicew': 153,\n",
       " 'ioctlsocket': 154,\n",
       " 'sendnotifymessagew': 155,\n",
       " 'getsystemdirectorya': 156,\n",
       " 'openscmanagerw': 157,\n",
       " 'setwindowshookexa': 158,\n",
       " 'internetconnecta': 159,\n",
       " 'getfileversioninfosizew': 160,\n",
       " 'getvolumepathnamew': 161,\n",
       " 'createremotethread': 162,\n",
       " 'getfileversioninfow': 163,\n",
       " 'lookupaccountsidw': 164,\n",
       " 'outputdebugstringa': 165,\n",
       " 'shellexecuteexw': 166,\n",
       " 'thread32first': 167,\n",
       " 'shgetspecialfolderlocation': 168,\n",
       " 'getusernamew': 169,\n",
       " 'createservicea': 170,\n",
       " 'wsasocketw': 171,\n",
       " 'getcomputernamew': 172,\n",
       " 'startservicea': 173,\n",
       " 'setfileinformationbyhandle': 174,\n",
       " 'getaddrinfow': 175,\n",
       " 'sendto': 176,\n",
       " 'cryptencrypt': 177,\n",
       " 'coinitializesecurity': 178,\n",
       " 'getbestinterfaceex': 179,\n",
       " 'getfileinformationbyhandle': 180,\n",
       " 'getcomputernamea': 181,\n",
       " 'cocreateinstanceex': 182,\n",
       " 'urldownloadtofilew': 183,\n",
       " 'bind': 184,\n",
       " 'unhookwindowshookex': 185,\n",
       " 'internetqueryoptiona': 186,\n",
       " 'globalmemorystatus': 187,\n",
       " 'setwindowshookexw': 188,\n",
       " 'cryptacquirecontexta': 189,\n",
       " 'certopenstore': 190,\n",
       " 'regdeletevaluea': 191,\n",
       " 'iwbemservices': 192,\n",
       " 'execquery': 193,\n",
       " 'cryptacquirecontextw': 194,\n",
       " 'getadaptersinfo': 195,\n",
       " 'regdeletekeya': 196,\n",
       " 'wsasocketa': 197,\n",
       " 'movefilewithprogressw': 198,\n",
       " 'getusernamea': 199,\n",
       " 'cryptexportkey': 200,\n",
       " 'getsystemwindowsdirectorya': 201,\n",
       " 'recv': 202,\n",
       " 'ntqueueapcthread': 203,\n",
       " 'getdiskfreespaceexw': 204,\n",
       " 'ntqueryfullattributesfile': 205,\n",
       " 'rtladdvectoredexceptionhandler': 206,\n",
       " 'internetcrackurla': 207,\n",
       " 'certcontrolstore': 208,\n",
       " 'listen': 209,\n",
       " 'ntsuspendthread': 210,\n",
       " 'rtlremovevectoredexceptionhandler': 211,\n",
       " 'httpopenrequesta': 212,\n",
       " 'wsarecv': 213,\n",
       " 'findresourceexa': 214,\n",
       " 'ntgetcontextthread': 215,\n",
       " 'httpsendrequesta': 216,\n",
       " 'internetgetconnectedstate': 217,\n",
       " 'getusernameexw': 218,\n",
       " 'getsockname': 219,\n",
       " 'internetcrackurlw': 220,\n",
       " 'module32firstw': 221,\n",
       " 'certcreatecertificatecontext': 222,\n",
       " 'httpqueryinfoa': 223,\n",
       " 'removedirectorya': 224,\n",
       " 'cryptunprotectmemory': 225,\n",
       " 'internetopenw': 226,\n",
       " 'internetconnectw': 227,\n",
       " 'httpopenrequestw': 228,\n",
       " 'httpsendrequestw': 229,\n",
       " 'copyfilew': 230,\n",
       " 'getdiskfreespacew': 231,\n",
       " 'accept': 232,\n",
       " 'ntdeletekey': 233,\n",
       " 'removedirectoryw': 234,\n",
       " 'rtladdvectoredcontinuehandler': 235,\n",
       " 'shutdown': 236,\n",
       " 'regdeletekeyw': 237,\n",
       " 'cryptprotectmemory': 238,\n",
       " 'ntquerymultiplevaluekey': 239,\n",
       " 'controlservice': 240,\n",
       " 'internetsetstatuscallback': 241,\n",
       " 'getfileversioninfoexw': 242,\n",
       " 'getfileversioninfosizeexw': 243,\n",
       " 'startservicew': 244,\n",
       " 'internetreadfile': 245,\n",
       " 'createservicew': 246,\n",
       " 'ntdeletevaluekey': 247,\n",
       " 'netshareenum': 248,\n",
       " 'system': 249,\n",
       " 'sendnotifymessagea': 250,\n",
       " 'getinterfaceinfo': 251,\n",
       " 'internetopenurlw': 252,\n",
       " 'deleteurlcacheentrya': 253,\n",
       " 'registerhotkey': 254,\n",
       " 'copyfileexw': 255,\n",
       " 'ntsetcontextthread': 256,\n",
       " 'ntterminatethread': 257,\n",
       " 'createjobobjectw': 258,\n",
       " 'findfirstfileexa': 259,\n",
       " 'certopensystemstorea': 260,\n",
       " 'wsaconnect': 261,\n",
       " 'deleteservice': 262,\n",
       " 'netgetjoininformation': 263,\n",
       " 'setinformationjobobject': 264,\n",
       " 'ntsavekey': 265,\n",
       " 'rtlcompressbuffer': 266,\n",
       " 'obtainuseragentstring': 267,\n",
       " 'rtlcreateuserthread': 268,\n",
       " 'assignprocesstojobobject': 269,\n",
       " 'deleteurlcacheentryw': 270,\n",
       " 'ntwritevirtualmemory': 271,\n",
       " 'wsasend': 272,\n",
       " 'netusergetinfo': 273,\n",
       " 'cryptprotectdata': 274,\n",
       " 'recvfrom': 275,\n",
       " 'enumservicesstatusw': 276,\n",
       " 'dnsquery': 277,\n",
       " 'execmethod': 278,\n",
       " 'a': 279,\n",
       " 'wsarecvfrom': 280,\n",
       " 'enumservicesstatusa': 281,\n",
       " 'rtldecompressbuffer': 282,\n",
       " 'messageboxtimeouta': 283,\n",
       " 'w': 284,\n",
       " 'createremotethreadex': 285,\n",
       " 'getusernameexa': 286,\n",
       " 'ntloadkey': 287,\n",
       " 'cryptgenkey': 288,\n",
       " 'cryptunprotectdata': 289,\n",
       " 'readcabinetstate': 290,\n",
       " 'certopensystemstorew': 291,\n",
       " 'internetgetconnectedstateexw': 292,\n",
       " 'wsasendto': 293,\n",
       " 'netusergetlocalgroups': 294,\n",
       " 'exitwindowsex': 295,\n",
       " 'encryptmessage': 296,\n",
       " 'ntunloaddriver': 297}"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tokenizer = Tokenizer()#对文本语料进行向量化\n",
    "tokenizer.fit_on_texts(df_train['api'].tolist())#基于texts构建词汇表 把texts喂入fit_on_texts方法里面去\n",
    "tokenizer.fit_on_texts(df_test['api'].tolist())\n",
    "vacab=tokenizer.word_index\n",
    "vacab"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-24-04c61298a3a4>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mx_train_word_ids\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtokenizer\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtexts_to_sequences\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf_train\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'api'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtolist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      2\u001b[0m \u001b[0mx_test_word_ids\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtokenizer\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtexts_to_sequences\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf_test\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'api'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtolist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx_train_word_ids\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'\\n'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx_test_word_ids\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/keras_preprocessing/text.py\u001b[0m in \u001b[0;36mtexts_to_sequences\u001b[0;34m(self, texts)\u001b[0m\n\u001b[1;32m    279\u001b[0m             \u001b[0mA\u001b[0m \u001b[0mlist\u001b[0m \u001b[0mof\u001b[0m \u001b[0msequences\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    280\u001b[0m         \"\"\"\n\u001b[0;32m--> 281\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0mlist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtexts_to_sequences_generator\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtexts\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    282\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    283\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0mtexts_to_sequences_generator\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtexts\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/keras_preprocessing/text.py\u001b[0m in \u001b[0;36mtexts_to_sequences_generator\u001b[0;34m(self, texts)\u001b[0m\n\u001b[1;32m    310\u001b[0m                                             \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfilters\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    311\u001b[0m                                             \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlower\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 312\u001b[0;31m                                             self.split)\n\u001b[0m\u001b[1;32m    313\u001b[0m             \u001b[0mvect\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    314\u001b[0m             \u001b[0;32mfor\u001b[0m \u001b[0mw\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mseq\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/keras_preprocessing/text.py\u001b[0m in \u001b[0;36mtext_to_word_sequence\u001b[0;34m(text, filters, lower, split)\u001b[0m\n\u001b[1;32m     61\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     62\u001b[0m     \u001b[0mseq\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtext\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msplit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msplit\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 63\u001b[0;31m     \u001b[0;32mreturn\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mseq\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     64\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     65\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "x_train_word_ids=tokenizer.texts_to_sequences(df_train['api'].tolist())\n",
    "x_test_word_ids=tokenizer.texts_to_sequences(df_test['api'].tolist())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'list'> \n",
      " <class 'list'>\n"
     ]
    }
   ],
   "source": [
    "print(type(x_train_word_ids),'\\n',type(x_test_word_ids))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "ename": "MemoryError",
     "evalue": "Unable to allocate 1.96 TiB for an array with shape (89806693, 6000) and data type int32",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mMemoryError\u001b[0m                               Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-27-54bdf4a4e6a1>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;31m#填充到固定长度 长的截取 短的补\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      2\u001b[0m \u001b[0mmax_len\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m6000\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mx_train_padded_seqs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mkeras\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpreprocessing\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msequence\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpad_sequences\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx_train_word_ids\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmaxlen\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmax_len\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      4\u001b[0m \u001b[0mx_test_padded_seqs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mkeras\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpreprocessing\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msequence\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpad_sequences\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx_test_word_ids\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmaxlen\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmax_len\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/keras_preprocessing/sequence.py\u001b[0m in \u001b[0;36mpad_sequences\u001b[0;34m(sequences, maxlen, dtype, padding, truncating, value)\u001b[0m\n\u001b[1;32m     83\u001b[0m                          .format(dtype, type(value)))\n\u001b[1;32m     84\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 85\u001b[0;31m     \u001b[0mx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfull\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnum_samples\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmaxlen\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0msample_shape\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdtype\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     86\u001b[0m     \u001b[0;32mfor\u001b[0m \u001b[0midx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0ms\u001b[0m \u001b[0;32min\u001b[0m \u001b[0menumerate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msequences\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     87\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/numpy/core/numeric.py\u001b[0m in \u001b[0;36mfull\u001b[0;34m(shape, fill_value, dtype, order)\u001b[0m\n\u001b[1;32m    323\u001b[0m     \u001b[0;32mif\u001b[0m \u001b[0mdtype\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    324\u001b[0m         \u001b[0mdtype\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0marray\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfill_value\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdtype\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 325\u001b[0;31m     \u001b[0ma\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mempty\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0morder\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    326\u001b[0m     \u001b[0mmultiarray\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcopyto\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfill_value\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcasting\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'unsafe'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    327\u001b[0m     \u001b[0;32mreturn\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mMemoryError\u001b[0m: Unable to allocate 1.96 TiB for an array with shape (89806693, 6000) and data type int32"
     ]
    }
   ],
   "source": [
    "#填充到固定长度 长的截取 短的补\n",
    "max_len=6000\n",
    "x_train_padded_seqs=keras.preprocessing.sequence.pad_sequences(x_train_word_ids, maxlen=max_len)\n",
    "x_test_padded_seqs=keras.preprocessing.sequence.pad_sequences(x_test_word_ids, maxlen=max_len)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#上面训练的vacab挺不容易的 所以保存一下为pickle文件\n",
    "import pickle#wb代表写也就是存储文件 rb就是读文件\n",
    "with open('./vacab.pkl','wb') as f:\n",
    "    pickle.dump(vacab,f)\n",
    "with open('./x_train_padded_seqs.pkl','wb') as f:\n",
    "    pickle.dump(x_train_padded_seqs,f)\n",
    "with open('./x_test_padded_seqs.pkl','wb') as f:\n",
    "    pickle.dump(x_test_padded_seqs,f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#搭建fasttext()\n",
    "def fasttext():\n",
    "    #搭建模型\n",
    "    model=kerasras.Sequential([\n",
    "        keras.layers.Embedding(len(vacab),256,input_length=max_len),\n",
    "        keras.layers.GlobalAveragePooling1D()#对文本数据进行平均池化操作\n",
    "        keras.layers.Dense(8,activation=\"softmax\")\n",
    "    ])\n",
    "    return model#返回这个网络model\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#切分一部分数据进行训练  暂未做\n",
    "from sklearn_model_selection import train_test_spilt\n",
    "X,y=x_train_padded_seqs,labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "model=fasttext()\n",
    "model.compile(loss=\"categorical_crossentropy\",metrics=['accuracy'],optimizer='adam')\n",
    "history=model.fit(X,y,batch=1024,epochs=10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "result=model.predict(x_test_padded_seqs)#后面流程就跟之前的一样了\n",
    "result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "result=pd.DataFrame(result, columns=['prob0', 'prob1', 'prob2', 'prob3', 'prob4', 'prob5', 'prob6', 'prob7'])\n",
    "result['file_id'] = df_test['file_id'].values\n",
    "columns=['file_id','prob0', 'prob1', 'prob2', 'prob3', 'prob4', 'prob5', 'prob6', 'prob7']\n",
    "result.to_csv('./fasttext1.csv', index=False, columns=columns)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
